<?php
include_once 'titulo.php';
if ($_SESSION['IdUsuario']) {
    ?>

    <html>
        <head>
            <title> Chamados</title>
            <?php
            include_once 'MySQL.php';
            include_once 'cabecalho.php';
            include_once 'script/functions.php';
            ?>

            <title>Vidracaria</title>
            <script type="text/javascript" src="script/jquery-1.6.3.min.js"></script>
            <script src="script/jquery.maskMoney.js" type="text/javascript"></script>
            <script type="text/javascript" src="script/jquery.maskedinput-1.3.min.js"></script>
            <script>
                $(function(){
                    $("#real").maskMoney({symbol:"R$",decimal:".",thousands:""});
                    $("#entrada").maskMoney({symbol:"R$",decimal:".",thousands:""});
                    $("#alterarPagamento").maskMoney({symbol:"R$",decimal:".",thousands:""});
                });
            </script>
            <script>
                jQuery(function($){
                    $("#reagendar").mask("99/99/9999");
                    $("#InserirServico").mask("99/99/9999");
                    $("#AlterarPaga").mask("99/99/9999");
                    $("#PesqConcluido").mask("(99) 9999-9999");
                });
            </script>
        </head>
        <body>
            <div class="total">
                <?php
                include_once 'titulo.php';
                ?>
                <div class="cabecalho">
                </div>
                <?php
                include_once 'menuHorizontal.php';
                ?>
                <div class="conteudo">
                    <div style='width: 98%; margin-left: auto; margin-right: auto; margin-top: 30px;'>    
                        <?php
                        $data = new functions();

                        //BOTÃO VOLTAR
                        echo "<form action='relatorio_comissaoInsImpre.php' >";
                        echo "<input type='submit' value='VOLTAR' class='btnVoltar'/>";
                        echo "</form><br/>";

                        echo "<table class='tblUsuarios'>";
                        echo "<thead>";
                        echo "<th>COD</th>";
                        echo "<th>SEXO</th>";
                        echo "<th>FUNCIONARIO</th>";
                        echo "<th>INICIO</th>";
                        echo "<th>FIM</th>";
                        echo "<th>EFETUADO EM</th>";
                        echo "<th>TOTAL_SER.</th>";
                        echo "<th>SALARIO</th>";
                        echo "<th>COMIS(%)</th>";
                        echo "<th>COMIS(R$)</th>";
                        echo "<th>LIQUIDO</th>";
                        echo "<th>USUARIO</th>";
                        echo "<th>ACOES</th>";
                        echo "</thead>";
                        echo "<tbody>";
                        $sql = "CALL sp_getPagamentosFuncionarioById('" . $_SESSION['FUNCIONARIO'] . "')";
                        $resultado = executaSQL($sql);

                        while ($linha = mysqli_fetch_array($resultado)) {
                            echo "<tr>";
                            echo "<td>" . $linha['fk_fun_id'] . "</td>";
                            //testo o valor do campo sexo, e coloco o texto apropriado na tabela
                            if ($linha["fun_sexo"] == "F") {
                                //echo "<td>" . "Feminino" . "</td>";
                                echo "<td>" . "<img src='style/imagens/female_user_icon256.png' style='display:block; margin-left:auto; margin-right:auto; width:30px; height:30px' />" . "</td>";
                            } else {
                                //echo "<td>" . "Masculino" . "</td>";
                                echo "<td>" . "<img src='style/imagens/male_user_icon256.png' style='display:block; margin-left:auto; margin-right:auto; width:30px; height:30px' />" . "</td>";
                            }

                            echo "<td>" . $linha['fun_nome'] . "</td>";
                            echo "<td>" . $inicio = $data->data_BRA($linha['pagf_dt_inicio']) . "</td>";
                            echo "<td>" . $fim = $data->data_BRA($linha['pagf_dt_fim']) . "</td>";
                            echo "<td>" . $linha['pagf_data'] . "</td>";
                            echo "<td>" . $linha['pagf_totalServico'] . "</td>";

                            echo "<td>" . $linha['pagf_salario'] . "</td>";
                            echo "<td>" . $linha['pagf_comissao'] . "</td>";
                            echo "<td>" . $linha['pagf_valor_comissao'] . "</td>";
                            echo "<td><label class='labelVermelha'>" . $linha['pagf_total'] . "</label></td>";
                            echo "<td>" . $linha['usu_nome'] . "</td>";

                            echo "<td>";
                            //deletar pagamento
                            if ($_SESSION['IdUsuario'] AND $_SESSION['IdUsuario'] == 1) {
                                echo "<form action='script/acoes.php' method='post' onsubmit='return confirm(\"Excluir Pagamento?\")'>";
                                echo "<input type='hidden' name='ACAO' value='deletePagamentoFunc'/>";
                                echo "<input type='hidden' name='ID' value='" . $linha['pagf_id'] . "'/>";
                                echo "<input type='submit' value='' class='btnExcluir'/>";
                            }
                            echo "</form><br/>";
                        }
                        echo "</table>";
                        ?>
                    </div>

                </div>
            </div>
        </body>
    </html>
    <?php
} else {
    header("location: session_expirada.php");
}
?>

<?php

function executaSQL($sql) {
    $mySQL = new MySQL;
    $resultado = $mySQL->execSP($sql);
    return $resultado;
}
?>
